package com.link.base.ext.emp.controller;


import com.link.base.ext.emp.dao.mybatis.mapper.ExtEmployeeMapper;
import com.link.base.ext.emp.model.ExtEmployee;
import com.link.base.ext.emp.service.ExtEmployeeService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.QueryParams;
import com.link.core.cllog.LCLogger;
import com.link.ext.basic.controller.BasicExtController;
import com.link.ext.basic.service.BasicExtService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/ext/extEmployee")
public class ExtEmployeeController extends BasicExtController<ExtEmployee> {

    @Resource
    private ExtEmployeeService extEmployeeService;
    @Resource
    private ExtEmployeeMapper extEmployeeMapper;

    @Override
    public BasicExtService<ExtEmployee> getBasicService() throws Exception {
        return extEmployeeService;
    }


    /**
     * 通用picklist
     */
    @RequestMapping(value = "/emppicklist", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> picklist(@JsonParam QueryParams qps, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            ExtEmployee t = (ExtEmployee) BasicModel.transformClass(ExtEmployee.class, qps);
            //设置安全性
            t.preDealSecurity(request);
            List<ExtEmployee> list = extEmployeeMapper.queryESBUsersByUserPage(t);
            result.put("success", true);
            result.put("rows", list);
            result.put("total", getCount(((BasicModel) t), list.size()));
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("rows", new ArrayList<ExtEmployee>());
            result.put("result", e.getMessage());
        }
        return result;
    }
}
